import 'package:flutter/material.dart';
import 'package:get/get_state_manager/get_state_manager.dart';
import 'package:industry_net/base/common/util.dart';
import 'package:industry_net/base/component/component.dart';
import 'package:industry_net/pages/me/setup/main/controller.dart';

class SetupPage extends GetView<SetupController> {
  const SetupPage({Key? key}) : super(key: key);

  Widget _getItem(
      {required String title,
      required String content,
      required VoidCallback onTap}) {
    return TitleContentItemView(
        padding: EdgeInsets.symmetric(horizontal: gap12),
        backgroundColor: ColorsUtil.white,
        onTap: onTap,
        title: title,
        content: content);
  }

  Widget _getLine() {
    return separatorLine(indent: gap12, endIndent: gap12);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: detailAppBar(context, title: '设置'),
      body: ListView(
        children: [
          Obx(() => TitleContentItemView(
                padding: EdgeInsets.symmetric(horizontal: gap12),
                backgroundColor: ColorsUtil.white,
                title: '设置头像',
                height: 80.w,
                onTap: controller.actionAvater,
                contentWidget: loadAvater(
                    url: controller.userCtrl.state.avater.value, size: 50.w),
              )),
          _getLine(),
          Obx(
            () => _getItem(
                title: '昵称',
                content: controller.userCtrl.state.nickName.value,
                onTap: controller.actionNickName),
          ),
          _getLine(),
          TitleContentItemView(
            padding: EdgeInsets.symmetric(horizontal: gap12),
            backgroundColor: ColorsUtil.white,
            title: '用户名',
            content: '1233444',
            contentStyle:
                pfMediumStyle(color: ColorsUtil.title, fontSize: font15),
            hasArrow: false,
          ),
          _getLine(),
          Obx(
            () => _getItem(
                title: '手机号',
                content: controller.state.phone.value.phone,
                onTap: controller.actionPhone),
          ),
          SizedBox(
            height: gap10,
          ),
          _getItem(
              title: '主体认证',
              content: '请认证',
              onTap: controller.actionCertification),
          _getLine(),
          _getItem(
              title: '登录密码设置',
              content: '去设置',
              onTap: controller.actionLoginPwd),
          SizedBox(
            height: gap10,
          ),
          Obx(
            () => _getItem(
                title: '清除缓存',
                content: controller.state.cacheSize.value,
                onTap: controller.actionClearCache),
          ),
          _getLine(),
          Obx(
            () => _getItem(
                title: '关于我们',
                content: controller.state.version.value,
                onTap: controller.actionAboutUs),
          )
        ],
      ),
      bottomNavigationBar: Padding(
        padding: EdgeInsets.symmetric(
            horizontal: 31.w, vertical: ScreenUtil().bottomBarHeight + gap15),
        child: ExpandedButton(
          text: '退出登录',
          onPressed: controller.actionLoginOut,
        ),
      ),
    );
  }
}
